package com.changgou.page.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @description:
 * @author: 大佬味的小男孩
 * @date: 2020-07-22 09:44
 **/
@Configuration
public class RabbitmqConfig {

    /*
     * 用来监听spu商品上架的
     * */
    //交换机名称
    public static final String GOODS_UP_EXCHANGE = "goods_up_exchange";
    // 定义队列名称
    public static final String SEARCH_ADD_QUEUE = "search_add_queue";

    //声明队列
    @Bean(SEARCH_ADD_QUEUE)
    public Queue AD_UPDATE_QUEUE() {
        return new Queue(SEARCH_ADD_QUEUE);
    }

    //声明交换机
    @Bean(GOODS_UP_EXCHANGE)
    public Exchange GOODS_UP_EXCHANGE() {
        return ExchangeBuilder.fanoutExchange(GOODS_UP_EXCHANGE).durable(true).build();
    }

    //队列绑定交换机
    @Bean
    public Binding GOODS_UP_EXCHANGE_BINDING(@Qualifier(SEARCH_ADD_QUEUE) Queue queue, @Qualifier(GOODS_UP_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }


    /*
     * 用来监听spu商品下架的
     * */
    //交换机名称
    public static final String GOODS_DOWN_EXCHANGE = "goods_down_exchange";
    // 定义队列名称
    public static final String SEARCH_DELETE_QUEUE = "search_delete_queue";

    //声明队列
    @Bean(SEARCH_DELETE_QUEUE)
    public Queue SEARCH_DELETE_QUEUE() {
        return new Queue(SEARCH_DELETE_QUEUE);
    }

    //声明交换机
    @Bean(GOODS_DOWN_EXCHANGE)
    public Exchange GOODS_DOWN_EXCHANGE() {
        return ExchangeBuilder.fanoutExchange(GOODS_DOWN_EXCHANGE).durable(true).build();
    }

    //队列绑定交换机
    @Bean
    public Binding GOODS_DOWN_EXCHANGE_BINDING(@Qualifier(SEARCH_DELETE_QUEUE) Queue queue, @Qualifier(GOODS_DOWN_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }


    /*
     * 用来监听商品上下架时生产静态页面
     * */
    // 定义队列名称
    public static final String PAGE_CREATE_QUEUE = "page_create_queue";

    //声明队列
    @Bean(PAGE_CREATE_QUEUE)
    public Queue PAGE_CREATE_QUEUE() {
        return new Queue(PAGE_CREATE_QUEUE);
    }

    //商品上下架交换机和对列的绑定
    @Bean
    public Binding PAGE_CREATE_BINDING(@Qualifier(PAGE_CREATE_QUEUE) Queue queue, @Qualifier(GOODS_UP_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }


    /*
     * 用来监听广告的
     * */
    //定义队列名称
    public static final String AD_UPDATE_QUEUE = "ad_update_queue";

    //声明队列
    @Bean
    public Queue queue() {
        return new Queue(AD_UPDATE_QUEUE);
    }
}
